﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Enferno.Public.Web.Components.Server.ViewModels;
using Enferno.Public.Web.Models;

namespace Enferno.Public.Web.Components.Server.Mappers
{
    public class PaymentResponseProfile : Profile
    {
        protected override void Configure()
        {
            Mapper.CreateMap<PaymentResponseModel, PaymentResponseViewModel>()
                .ForMember(to => to.RedirectParameters, opts => opts.ResolveUsing<ParameterResolver>());
        }
    }

    public class ParameterResolver : ValueResolver<PaymentResponseModel, IDictionary<string, string>>
    {
        protected override IDictionary<string, string> ResolveCore(PaymentResponseModel source)
        {
            return source.RedirectParameters.ToDictionary(nameValue => nameValue.Name, nameValue => nameValue.Value);
        }
    }
}
